<template>
  <j-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
      
        <!-- <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId" label="许愿人id">
          <a-input placeholder="请输入许愿人id" v-model="model.userId" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wishType" label="许愿种类">
          <a-input-number v-model="model.wishType"/>
        </a-form-model-item> -->
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="comments" label="评论">
          <a-textarea placeholder="请输入评论" v-model="model.comments" />
        </a-form-model-item>
        <!-- <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content" label="许愿内容">
          <a-input placeholder="请输入许愿内容" v-model="model.content" />
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isOpen" label="是否公开（0：是；1:否）">
          <a-input-number v-model="model.isOpen"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isLike" label="是否点赞（0：是；1：否）">
          <a-input-number v-model="model.isLike"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isShield" label="是否屏蔽（0：是；1：否）">
          <a-input-number v-model="model.isShield"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isWish" label="是否还愿（0：是；1：否）">
          <a-input-number v-model="model.isWish"/>
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="creationTime" label="创建时间">
          <a-date-picker showTime valueFormat='YYYY-MM-DD HH:mm:ss' v-model="model.creationTime" />
        </a-form-model-item> -->
		
      </a-form-model>
    </a-spin>
  </j-modal>
</template>

<script>
  import { getAction } from '@/api/manage'
  import moment from "moment"

  export default {
    name: "BusTreviFountainPcModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        },
        url: {
          add: "/fountainPc/busTreviFountainPc/comments",
          edit: "/fountainPc/busTreviFountainPc/comments",
        },
        validatorRules:{
          comments:[{ required: true, message: '请输入评论' }],
        },
        id:''
      }
    },
    created () {
    },
    methods: {
      add () {
        //初始化默认值
        this.edit({});
      },
      edit (record) {
        // this.model = Object.assign({}, record);
        console.log(this.model.comments,'model');
        this.id = record.id
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.$refs.form.clearValidate();
      },
      handleOk () {
        const that = this;
        // 触发表单验证
         this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            if(!this.model.id){
              httpurl+=this.url.edit;
            }
            const params = {
              comments:this.model.comments,
              id:this.id
            }
            getAction(httpurl,params).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                this.model.comments = ''
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }else{
             return false;
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style lang="less" scoped>

</style>